package org.hzero.exam.api.controller.v1;

import io.choerodon.core.domain.Page;
import io.choerodon.core.iam.ResourceLevel;
import io.choerodon.mybatis.pagehelper.PageHelper;
import io.choerodon.mybatis.pagehelper.domain.PageRequest;
import io.choerodon.swagger.annotation.Permission;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.hzero.core.base.BaseController;
import org.hzero.core.util.Results;
import org.hzero.exam.config.SwaggerTags;
import org.hzero.exam.domain.entity.HodrCompany;
import org.hzero.exam.domain.entity.HodrCustomer;
import org.hzero.exam.domain.repository.HodrCustomerRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 马旭阳
 * @date2019/8/5
 */
@Api(tags = SwaggerTags.CUSTOMER)
@RestController("customerController.v1")
@RequestMapping("/v1/{organizationId}/customers")
public class HodrCustomerController extends BaseController {
    @Autowired
    private HodrCustomerRepository customerRepository;
    @Permission(level = ResourceLevel.SITE)
    @ApiOperation(value = "根据客户编号或客户名称分页查询客户信息")
    @GetMapping
    public ResponseEntity<Page<HodrCustomer>> selectByCustomerNumberAndName(@PathVariable Long organizationId,
                                                                            @ApiParam(value = "客户编号")  String customerNumber,
                                                                            @ApiParam(value = "客户名称")  String customerName,
                                                                            PageRequest pageRequest){
        return Results.success(PageHelper.doPage(pageRequest,()->customerRepository.selectByCustomerNumberAndName(customerNumber,customerName)));
    }
}
